package com.lelouch.controller;

import com.lelouch.common.JsonData;
import com.lelouch.dto.AclModuleLevelDto;
import com.lelouch.dto.DeptLevelDto;
import com.lelouch.param.AclModuleParam;
import com.lelouch.service.SysAclModuleService;
import com.lelouch.service.SysTreeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;


/**
 * 权限模块控制器
 *
 * @author lcy
 * @create 2018-06-21 10:45
 */
@Controller
@Slf4j
@RequestMapping("/sys/aclModule")
public class SysAclModuleController {
    @Autowired
    private SysAclModuleService sysAclModuleService;

    @Autowired
    private SysTreeService sysTreeService;


    @RequestMapping("/acl.page")
    @ResponseBody
    public ModelAndView index(){
        return new ModelAndView("acl");
    }


    /**
     * 新增权限
     * @param
     * @return
     */
    @RequestMapping("/save.json")
    @ResponseBody
    public JsonData save(AclModuleParam aclModuleParam){
        sysAclModuleService.save(aclModuleParam);
        return JsonData.success("新添权限成功");
    }



    /**
     * 更新权限信息
     * @param
     * @return
     */
    @RequestMapping("/update.json")
    @ResponseBody
    public JsonData update(AclModuleParam aclModuleParam){
        sysAclModuleService.update(aclModuleParam);
        return JsonData.success("更新权限成功");
    }


    /**
     * 列出权限树
     * @return
     */
    @RequestMapping("/tree.json")
    @ResponseBody
    public JsonData tree() {
        List<AclModuleLevelDto> dtoList = sysTreeService.aclModuleTree();
        return JsonData.success(dtoList);
    }

    @RequestMapping("/delete.json")
    @ResponseBody
    public JsonData delete(@RequestParam("aclModuleId") Integer aclModuleId){
        sysAclModuleService.delele(aclModuleId);
        return JsonData.success("删除权限成功");
    }
}
